package com.gzz.orchid.common.core.tuple;

import com.gzz.orchid.common.core.exception.ValidationException;
import com.gzz.orchid.common.core.util.I18nUtil;
import lombok.Value;

import java.util.Objects;

/**
 * 百分比
 *
 * @author higmd
 */
@Value
public class Percent {
    Integer value;
    // 构造函数
    public Percent(Integer value) {
        if (Objects.isNull(value) || value > 100 || value < 0) {
            throw new ValidationException(I18nUtil.ofMessage("百分比值必须在 0-100 之间"));
        }
        this.value = value;
    }

    public static Percent of(Integer value) {
        return new Percent(value);
    }
}
